<template>
  <div v-if="totalPages > 1" class="pagination">
    <button :disabled="currentPage === 1" @click="prevPage" class="page-btn prev-btn">
      上一页
    </button>
    <span class="page-info">第 {{ currentPage }} / {{ totalPages }} 页</span>
    <button :disabled="currentPage === totalPages" @click="nextPage" class="page-btn next-btn">
      下一页
    </button>
  </div>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()

const props = defineProps({
  currentPage: {
    type: Number,
    required: true,
  },
  totalPages: {
    type: Number,
    required: true,
  },
})

const emit = defineEmits(['update:currentPage'])

const prevPage = () => {
  const newPage = props.currentPage - 1
  if (newPage >= 1) {
    emit('update:currentPage', newPage)
    window.scrollTo({ top: 0, behavior: 'smooth' })
    router.replace({ query: { ...route.query, page: newPage } })
  }
}

const nextPage = () => {
  const newPage = props.currentPage + 1
  if (newPage <= props.totalPages) {
    emit('update:currentPage', newPage)
    window.scrollTo({ top: 0, behavior: 'smooth' })
    router.replace({ query: { ...route.query, page: newPage } })
  }
}

defineOptions({ name: 'AlbumPagination' })
</script>

<style lang="scss" scoped>
// 分页控件 - 简约大气设计
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0; // 减少按钮和页码之间的间距
  margin: 5rem 0 2rem 0;
  padding: 0 1rem;

  .page-btn {
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    color: #4a5568;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);

    &:hover:not(:disabled) {
      background: #f8fafc;
      border-color: #cbd5e0;
      color: #2d3748;
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    &:disabled {
      background: #f7fafc;
      border-color: #e2e8f0;
      color: #a0aec0;
      cursor: not-allowed;
      transform: none;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }
  }

  .page-info {
    color: #718096;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0 1rem;
    white-space: nowrap;
  }
}

// 响应式调整
@media (max-width: 768px) {
  .pagination {
    gap: 0; // 移动端进一步减少间距
    margin: 5rem 0 1.5rem 0;

    .page-btn {
      font-size: 0.8125rem;
      padding: 0.625rem 1.25rem;
      min-width: 90px;
    }

    .page-info {
      font-size: 0.8125rem;
      padding: 0 0.75rem;
    }
  }
}

@media (max-width: 480px) {
  .pagination {
    gap: 1rem; // 小屏幕进一步减少间距
    margin: 2rem 0 1rem 0;

    .page-btn {
      font-size: 0.75rem;
      padding: 0.5rem 1rem;
      min-width: 80px;
    }

    .page-info {
      font-size: 0.75rem;
      padding: 0 0.5rem;
    }
  }
}

// 暗色模式适配
:deep(html.dark) {
  .pagination {
    .page-btn {
      background: #2d3748;
      border-color: #4a5568;
      color: #e2e8f0;

      &:hover:not(:disabled) {
        background: #4a5568;
        border-color: #718096;
        color: #f7fafc;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
      }

      &:disabled {
        background: #1a202c;
        border-color: #2d3748;
        color: #718096;
      }
    }

    .page-info {
      color: #a0aec0;
    }
  }
}
</style>
